//package com.gitee.zhangchenyan.service.server;
//
//import com.alibaba.nacos.common.utils.StringUtils;
//import com.gitee.zhangchenyan.service.common.AlibabaNacos;
//import lombok.extern.slf4j.Slf4j;
//import lombok.val;
//import org.reflections.Reflections;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.ApplicationContextAware;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Service;
//
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Set;
//
//@Slf4j
//@Component
//public class ServiceServerBean implements ApplicationContextAware {
//
//    @Value("${takin.rpc.server.package.scan}")
//    private String packageScan;
//    public final static Map<String, String> SERVICE_MAP = new HashMap<>();
//    public final static Map<String, Object> SERVICE_BEAN = new HashMap<>();
//
//
//    @Override
//    public void setApplicationContext(ApplicationContext applicationContext) {
//        try {
//
//            Reflections reflections = new Reflections(packageScan);//创建一个Reflections 对象，并指定要扫描的包路径
//            Set<Class<?>> typesAnnotatedWith = reflections.getTypesAnnotatedWith(Service.class);//该方法会扫描指定包路径下带有@RpcService注解的类的Class对象，并封装成一个set集合
//            for (Class<?> aClass : typesAnnotatedWith) {
//                try {
//                    if (aClass.isAnnotationPresent(Service.class)) {
//                        Service annotation = aClass.getAnnotation(Service.class);
//                        Object o = aClass.newInstance();//遍历set集合，通过反射创建Class的对象
//                        val interfaces = o.getClass().getInterfaces();
//                        for (Class<?> anInterface : interfaces) {
//                            SERVICE_MAP.put(o.getClass().getName(), anInterface.getName());//以@RpcService的name属性为key放到Bean容器中
//                            log.info(String.format("BEAN加载[%s]成功!", o.getClass().getName()));
//                        }
//
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//            Map<String, Object> serviceBeanMap = applicationContext.getBeansWithAnnotation(Service.class);
//            if (serviceBeanMap.size() > 0) {
//                for (Object serviceBean : serviceBeanMap.values()) {
//                    val serviceBeanClassName = serviceBean.getClass().getAnnotatedSuperclass().getType().getTypeName();
//                    val interfaceName = SERVICE_MAP.get(serviceBeanClassName);
//                    if (StringUtils.isNotBlank(interfaceName)) {
//                        SERVICE_BEAN.put(interfaceName, serviceBean);
//                        log.info(String.format("BEAN加载[%s]成功!", serviceBeanClassName));
//                    }
//                }
//            }
//        } catch (Exception e) {
//            log.error("BEAN加载过程异常:" + e.getMessage());
//            e.printStackTrace();
//        }
//    }
//}
